<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Control extends CI_Controller {
	
	public function __contruct(){
		
	}
	
	public function login(){
		$username = $this->input->post('username');
		$password = $this->input->post('password');
		$radio = $this->input->post('radio');
		$data = [];
		switch($radio){
			case 1:
				$data = $this->student_login($username,$password);
				break;
			case 2:
				$data = $this->teacher_login($username,$password);
				break;
			default:
				echo 'error';
				return ;
		}
		$data['radio'] = $radio;
		$this->load->view('control',$data);
	}
	
	private function teacher_login($username,$password){
		$this->load->model('teacher_model');
		$reData['user'] = $this->teacher_model->login($username,$password);
		$reData['ths'] = [
			'教师信息'=>base_url('index.php/teacher/info/'.$reData['user']['classid']),
			'分数'=>base_url('index.php/teacher/score/'.$reData['user']['classid'])
		]; 
		if($reData['user']['isMinister']){
			$reData['ths']['部长评价'] = base_url('index.php/teacher/marking_stepTeacherList/'.$reData['user']['did']);
		}
		return $reData;
	}
	
	private function student_login($username,$password){
		$this->load->model('student_model');
		$reData['user'] = $this->student_model->login($username,$password);
		$reData['ths'] = [
			'学生信息'=>base_url('index.php/student/info/'.$reData['user']['classid']),
			'教评'=>base_url('index.php/student/marking_stepTeacherList/'.$reData['user']['classid'])
		];
		return $reData;
	}
	
	private function showView($view,$data){
		if($data){
			$this->load->view($view,$data);
		}else{
			$this->load->view('welcome_message');
		}
	}
	
}

?>